import { Popconfirm } from 'antd'
import styles from './index.module.less'

export const getColumns = (/* onOpen, onDelete */) => [
  {
    id: 0,
    dataIndex: 'name',
    title: '剧本名称',
    width: 300
  },
  {
    id: 1,
    dataIndex: 'tags',
    title: '剧本标签'
  },
  {
    id: 2,
    title: '剧本类型',
    render: row => <>{row?.wf_data?.type}</>
  },
  {
    id: 3,
    dataIndex: 'is_system',
    title: '剧本来源',
    render: text => <>{text ? '内置' : '自定义'}</>
  },
  // {
  //   id: 4,
  //   dataIndex: 'version',
  //   title: '剧本版本'
  // },
  {
    id: 5,
    dataIndex: 'control',
    title: '关联调度'
  },
  {
    id: 6,
    dataIndex: 'admin',
    title: '创建人'
  },
  {
    id: 7,
    dataIndex: 'right',
    title: '权限组'
  },
  {
    id: 8,
    dataIndex: 'created_at',
    title: '创建时间'
  }
]

export const getOperationItemConfig = (onOpen, onDelete) => record => {
  return [
    {
      title: '调度',
      click: () => {
        onOpen('control', record)
      }
    },
    {
      title: '查看',
      click: () => {
        onOpen('check', record)
      }
    },
    {
      title: '编辑',
      click: () => {
        onOpen('update', record)
      }
    },
    {
      title: '复制',
      click: () => {
        onOpen('copy', record)
      }
    },
    {
      title: '删除',
      render: () => {
        return (
          <Popconfirm
            title="您确定要删除吗?"
            onConfirm={() => onDelete({ ids: [record.id] })}
            okText="确定"
            cancelText="取消"
          >
            <span className={styles['operation_btn']}>删除</span>
          </Popconfirm>
        )
      }
    }
  ]
}

export const playBaseformConfigs = [
  {
    id: 1,
    type: 'Input',
    formItemProps: {
      label: '剧本名称',
      name: 'name',
      rules: [
        {
          required: true,
          message: '请输入1~30个字符，支持中文、英文、数字、.和下划线'
        }
      ]
    },
    props: {
      placeholder: '请输入剧本名称'
    }
  },
  // {
  //   id: 2,
  //   type: 'Input',
  //   formItemProps: {
  //     label: '剧本版本',
  //     name: 'version',
  //     rules: [{ required: true, message: '请输入剧本版本'}]
  //   },
  //   props: {
  //     placeholder: '请输入剧本版本'
  //   }
  // },
  {
    id: 3,
    type: 'Select',
    formItemProps: {
      label: '剧本类型',
      name: 'type',
      rules: [{ required: true, message: '请输入剧本类型' }]
    },
    props: {
      placeholder: '请输入剧本类型',
      options: [
        {
          label: '告警处置',
          value: '告警处置'
        },
        {
          label: '日常运维',
          value: '日常运维'
        }
      ]
    }
  },
  {
    id: 4,
    type: 'Select',
    formItemProps: {
      label: '剧本标签',
      name: 'tags'
    },
    props: {
      placeholder: '请输入剧本标签，最多10个',
      mode: 'tags',
      maxTagCount: 10
    }
  },
  {
    id: 5,
    type: 'TextArea',
    formItemProps: {
      label: '剧本描述',
      name: 'description'
    },
    props: {
      placeholder: '请输入剧本描述'
    }
  }
]
